

#import "FAMHomeWriteFoodView.h"
@interface FAMHomeWriteFoodView()
@property (weak, nonatomic) IBOutlet UITextField *FAMNameTextField;
@property (weak, nonatomic) IBOutlet UIView *FAMNameBackView;
@property (weak, nonatomic) IBOutlet UIView *FAMWeightBackView;
@property (weak, nonatomic) IBOutlet UITextField *FAMWeightTextField;
@end
@implementation FAMHomeWriteFoodView
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        NSArray *array = [[NSBundle mainBundle] loadNibNamed:@"FAMHomeWriteFoodView" owner:self options:nil];
        self = array.firstObject;
        [self FAM_showUi];
    }
    return self;
}
- (void)FAM_showUi{
    self.FAMNameBackView.layer.borderWidth = 1;
    self.FAMNameBackView.layer.borderColor = kCustom0xColor(0xBABABA, 1.0).CGColor;
    self.FAMWeightBackView.layer.borderWidth = 1;
    self.FAMWeightBackView.layer.borderColor = kCustom0xColor(0xBABABA, 1.0).CGColor;
}
- (void)layoutSubviews{
    [super layoutSubviews];
    self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
}
- (IBAction)FAM_confirmButtonClick:(UIButton *)sender {
    if ([[NSString nullToString:self.FAMNameTextField.text] isEqualToString:@""]) {
        [UIWindow.currentViewController showHint:@"Please enter the food name"];
        return;
    }
    if ([[NSString nullToString:self.FAMWeightTextField.text] isEqualToString:@""]) {
        [UIWindow.currentViewController showHint:@"Please enter food weight"];
        return;
    }
    WeakSelf(self);
    [UIWindow.currentViewController showHudInKeyWindowWithHint:nil];
    NSMutableDictionary *parametersDic = [NSMutableDictionary dictionary];
    [parametersDic setValue:_FAMCateType forKey:@"cate_type"];
    [parametersDic setValue:self.FAMNameTextField.text forKey:@"food_name"];
    [parametersDic setValue:self.FAMWeightTextField.text forKey:@"weight"];
    [parametersDic setValue:[FAMUserManger shareInstance].FAMTimer forKey:@"fmt_date"];
    [FAMHttpTool FAM_PostFoodmateFoodrecordWithParameters:[NSMutableDictionary dictionaryWithDictionary:@{@"data":parametersDic}] success:^(FAMFoodrecordModel * _Nonnull model, NSString * _Nonnull msg) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIWindow.currentViewController hideHudKeyWindow];
            [UIWindow.currentViewController performSelector:@selector(FAM_loadData:isFirst:) withObject:weakSelf.FAMDate withObject:@(YES)];
            [weakSelf removeFromSuperview];
        });
    } failure:^(NSString * _Nonnull errorInfo) {
        dispatch_async(dispatch_get_main_queue(), ^{
            [UIWindow.currentViewController hideHudKeyWindow];
            [UIWindow.currentViewController showHint:errorInfo];
        });
    }];
    
}
- (IBAction)FAM_closeButtonClick:(UIButton *)sender {
    [self removeFromSuperview];
}
- (void)setFAMCateType:(NSString *)FAMCateType{
    _FAMCateType = FAMCateType;
}
- (void)setFAMDate:(NSString *)FAMDate{
    _FAMDate = FAMDate;
}
@end
